export async function aiQuestion(question) {
  const apiKey = "sk-dfd22d727bd340b1a435d2c546e73b9c";
  const url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
  const body = {
    model: "qwen-turbo",
    messages: [
      { role: "system", content: "你是一个健康咨询助手，请用简洁、专业的中文回答用户问题。" },
      { role: "user", content: question }
    ]
  };

  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${apiKey}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify(body)
    });

    if (!response.ok) {
      throw new Error("API请求失败");
    }

    const data = await response.json();
    const answer = data?.choices?.[0]?.message?.content || "AI未能给出答案";
    return { success: true, data: { answer } };
  } catch (error) {
    return { success: false, error: error.message };
  }
} 